package itheima.com.MyTree;

public class Student implements Comparable<Student> {
    private String name;
    private int chinese;
    private int english;
    private int math;


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", chinese=" + chinese +
                ", english=" + english +
                ", math=" + math +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getChinese() {
        return chinese;
    }

    public void setChinese(int chinese) {
        this.chinese = chinese;
    }

    public int getEnglish() {
        return english;
    }

    public void setEnglish(int english) {
        this.english = english;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public Student(String name, int chinese, int english, int math) {
        this.name = name;
        this.chinese = chinese;
        this.english = english;
        this.math = math;
    }

    public Student() {
    }

    public int getSum() {
        return chinese + english + math;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (chinese != student.chinese) return false;
        if (english != student.english) return false;
        if (math != student.math) return false;
        return name != null ? name.equals(student.name) : student.name == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + chinese;
        result = 31 * result + english;
        result = 31 * result + math;
        return result;
    }

    @Override
    public int compareTo(Student o) {
        int result = this.getSum() - o.getSum();
        result = result == 0 ? this.getChinese() - o.getChinese() : result;
        result = result == 0 ? this.getEnglish() - o.getEnglish() : result;
        result = result == 0 ? this.getMath() - o.getMath() : result;
        result = result == 0 ? this.getName().compareTo(o.getName()) : result;
        return result;
    }
}
